use chrono::Local;
use serde::{Deserialize, Serialize};
use sqlx::types::chrono::DateTime;
use struct_field_names_as_array::FieldNamesAsSlice;

// 产品详情数据
#[derive(sqlx::FromRow, Deserialize, Serialize, FieldNamesAsSlice)]
pub struct ProductDetail{ 
    pub id: i64,
    // 分类id
    pub tid: i64,
    // 名称
    pub name: String, 
    // SEO名称
    pub seo_title: String, 
    // SEO关键字
    pub seo_keywords: String, 
    // SEO描述
    pub seo_description: String, 
    // 图片
    pub image: String,
    // 售卖url
    pub url: String,
    // 价格
    pub price: f64,
    // 点击
    pub hits: i64,
    // 内容
    pub content: String,
    pub created_at: DateTime<Local>
}


// 产品列表行数据
#[derive(sqlx::FromRow, Deserialize, Serialize, FieldNamesAsSlice)]
pub struct ProductRow { 
    pub id: i64,
    pub tid: i64,
    pub name: String, 
    pub image: String,
    pub hits: i64,
    pub taxon_name: String,
    pub created_at: DateTime<Local>
}

// 产品分页结果
#[derive(Serialize, Deserialize)]
pub struct ProductListResp {
    pub paginate: String,
    pub list: Vec<ProductRow>
}
